import 'dart:io';

import 'package:flutter/material.dart';
import 'package:gzmall_app/common/api.dart';
import 'package:gzmall_app/common/net_util.dart';
import 'package:gzmall_app/model/setting.dart';

class SettingUtil {
  static String appStoreAudit = 'false';
  static String termOfServiceUrl = '';
  static String cityOrDistrict = 'district';
  static String appName = '';
  static String iDLDUrl = '';
  static String aDLDUrl = '';
  static String iQRUrl = '';
  static String aQRUrl = '';
  static String tel = '';

  static init(BuildContext context) {
    NetUtil.get(context, Api.settings, (data, message) {
      List<Setting> _settings = (data as List)
          ?.map((e) => e == null ? null : Setting.fromJson(e))
          ?.toList();
      for (var s in _settings) {
        if (s.key.contains("app_store_audit")) {
          if (Platform.isIOS) {
            appStoreAudit = s.value;
          }
        }
        if (s.key.contains("term_of_service_url")) {
          termOfServiceUrl = s.value;
        }
        if (s.key.contains("city_or_district")) {
          cityOrDistrict = s.value;
        }
        if (s.key.contains("app_name")) {
          appName = s.value;
        }
        if (s.key.contains("ios_download_url")) {
          iDLDUrl = s.value;
        }
        if (s.key.contains("android_download_url")) {
          aDLDUrl = s.value;
        }
        if (s.key.contains("ios_qrcode_url")) {
          iQRUrl = s.value;
        }
        if (s.key.contains("android_qrcode_url")) {
          aQRUrl = s.value;
        }
        if (s.key.contains("tel")) {
          tel = s.value;
        }
      }
    }, isShowLoading: true);
  }

  static bool isAppStoreAudit() {
    return Platform.isIOS && SettingUtil.appStoreAudit == "true";
  }
}
